package cn.sylinx.horm.example.section13;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import cn.sylinx.horm.core.SqlClient;
import cn.sylinx.horm.dialect.fs.FS;

@Profile("section13")
@Component
public class Section13 implements CommandLineRunner {

    private SqlClient sqlClient;

    public Section13(SqlClient sqlClient) {
        this.sqlClient = sqlClient;
    }

    @Override
    public void run(String... args) throws Exception {

        // 创建对象
        MyExample13 my = new MyExample13();
        my.setFieldName("field_name");
        my.setFieldNumber("field_number");
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("a", "a");
        jsonMap.put("b", 1);
        my.setFieldExtra(jsonMap);
        Serializable pk = sqlClient.save(my);
        System.out.println("save pk -> " + pk);

        // 查询
        List<MyExample13> dataList = sqlClient.query(FS.of(MyExample13.class));
        System.out.println("dataList ->" + dataList);
    }
}
